package com.OtherExercises;

import java.util.Scanner;

public class 评委打分 {
    public static void main(String[] args) {
        getAverageScore(6);
    }

    /*
 请第1个评委打分:100
请第2个评委打分:90
请第3个评委打分:100
请第4个评委打分:60
请第5个评委打分:80
请第6个评委打分:100
最终得分是:92.5
*/


    /**
     * 根据输入的评委人数,创建数组,让评委打分,去掉最高最低分后计算平均分作为最终分
     *
     * @param num
     * @return double
     */
    public static double getAverageScore(int num) {
        int[] scores = new int[num];
        //遍历数组,录入评委的打分
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; i++) {
            System.out.print("请第" + (i + 1) + "个评委打分:");
            scores[i] = sc.nextInt();
        }

        //从数组中找出最高分,最低分,并计算平均分
        int sum = 0, max = scores[0], min = scores[0];
        for (int i = 0; i < scores.length; i++) {
            sum += scores[i];
            if (max < scores[i]) {
                max = scores[i];
            }
            if (min > scores[i]) {
                min = scores[i];
            }
        }
        double average = 1.0 * (sum - max - min) / (num - 2);
        System.out.println("最终得分是:" + average);
        return average;
    }

}
